package cn.scw.common.utils.sql;

import org.apache.commons.lang3.StringUtils;

/**
 * @description:
 * @author: lj
 * @create: 2019/8/22 9:24
 */
public class JpaUtil {
    private static String str_like="%";

    /**
     * %-str-%
     */
    public static String getLikeStr(String str) {
        if (StringUtils.isBlank(str)) {
            return str_like;
        } else {
            return str_like + str + str_like;
        }
    }

    /**
     * "" or  %-str-%
     */
    public static String getNullOrLikeStr(String str) {
        if (StringUtils.isBlank(str)) {
            return "";
        } else {
            return str_like + str + str_like;
        }
    }

    /**
     * %-str
     */
    public static String getPrefixLikeStr(String str) {
        if (StringUtils.isBlank(str)) {
            return str_like;
        } else {
            return str_like + str;
        }
    }

    /**
     * str-%
     */
    public static String getSuffixLikeStr(String str) {
        if (StringUtils.isBlank(str)) {
            return str_like;
        } else {
            return str + str_like;
        }
    }


    public static String getNullStr(String str) {
        if (StringUtils.isBlank(str)) {
            return "";
        }
        return str;
    }

    public static String getEqualOrAll(String str) {
        if (StringUtils.isBlank(str)) {
            return str_like;
        }
        return str;
    }
}
